<?php
    require_once '../config/config.php';
    require_once '../inc/db.php';

    // Get saved place
    $stmt = $mysqli->prepare("SELECT * from newsletter_visitors");
    if ($stmt) {
        if($stmt->execute()){
            $stmt->bind_result($id,$ip,$city,$country,$region,$link,$link_id,$datetime);
            $i = 0;
            while ($stmt->fetch()) {
                $places[$i]['ip'] = $ip;
                $places[$i]['id'] = $id;
                $places[$i]['city'] = $city;
                $places[$i]['country'] = $country;
                $places[$i]['region'] = $region;
                $places[$i]['link'] = $link;
                $places[$i]['link_id'] = $link_id;
                $places[$i]['datetime'] = $datetime;
                $i++;
            }
            $stmt->close();
        }
    }
 ?>
<?php $page = 'log'; ?>
<?php include 'inc/header.php'; ?>
            <br>
            <br>
            <br>
            <div class="col-md-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title">Log for visitor</h3>
                    </div>
                    <table class="table">
                        <thead>
                            <tr>
                                <td><strong>id</strong></td>
								<td><strong>ip</strong></td>
								<td><strong>city</strong></td>
								<td><strong>country</strong></td>
								<td><strong>region</strong></td>
								<td><strong>link viewed</strong></td>
								<td><strong>datetime</strong></td>
                            </tr>
                        </thead>
                         <?php if(isset($places)) { ?>
                            <?php foreach ($places as $place) { ?>
                                <tr>
					                <td><?php echo $place['id']; ?></td>
                                    <td><?php echo $place['ip']; ?></td>
					                <td><?php echo $place['city']; ?></td>
					                <td><?php echo $place['country']; ?></td>
					                <td><?php echo $place['region']; ?></td>
					                <td><?php echo $place['link']; ?></td>
					                <td><?php echo $place['datetime']; ?></td>
                                </tr>
                            <?php }//end foreach
                            }//end if ?>
                        </ul>
                    </table>
                </div>
            </div>
        </div>

        <!-- Script -->
        <script src="js/jquery.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </body>
</html>
<?php
    if (isset($mysqli)) {
        mysqli_close($mysqli);
    }
?>
